import ObsClient from "esdk-obs-browserjs/src/obs";
export const uploadFile = (v) => {
  return new Promise((resolve, reject) => {
    let file = v.file.name;
    let path = "type/"; //路径 可以为空
    //华为云OBS域名
    const obs_url = "obs.cn-east-3.myhuaweicloud.com/";
    //华为云OSSaccessKeyId
    const accessKeyId = "2MHEJUKIUMQAMGEAKLNC";
    const secretAccessKey = "MEZYydh9EmSlrqWKKYbxm9b1s4BOgoAo4rYZLDaa";
    const bucket = "lxssmall"; //桶名
    const uploadUrl = "https://" + bucket + "." + obs_url + path + file;

    var obsClient = new ObsClient({
      access_key_id: accessKeyId, //你的ak
      secret_access_key: secretAccessKey, // 你的sk
      server: obs_url, // 你的endPoint
    });
    obsClient.putObject(
      {
        Bucket: bucket, // 桶名
        Key: path + file, // 路径 + 文件名
        SourceFile: v.file,
      },
      function (err, result) {
        if (err) {
          reject(err);
        } else {
          resolve(uploadUrl);
        }
      }
    );
  });
};
